using System;
using System.Collections.Generic;
using Volo.Abp.EventBus.Distributed;

namespace Matrix.ServiceDiscovery.Events
{
    /// <summary>
    /// 服务变更事件
    /// </summary>
    public class ServiceChangedEto : IDistributedEvent
    {
        /// <summary>
        /// 事件类型：Create, Update, Delete, Activate, Deactivate
        /// </summary>
        public string EventType { get; set; } = string.Empty;

        /// <summary>
        /// 服务ID
        /// </summary>
        public Guid ServiceId { get; set; }

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 服务类型
        /// </summary>
        public string ServiceType { get; set; } = string.Empty;

        /// <summary>
        /// 旧值（用于更新事件）
        /// </summary>
        public string? OldValue { get; set; }

        /// <summary>
        /// 新值
        /// </summary>
        public string? NewValue { get; set; }

        /// <summary>
        /// 变更者
        /// </summary>
        public string ChangedBy { get; set; } = string.Empty;

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 变更详情
        /// </summary>
        public Dictionary<string, object> ChangeDetails { get; set; } = new();
    }

    /// <summary>
    /// 服务实例变更事件
    /// </summary>
    public class ServiceInstanceChangedEto : IDistributedEvent
    {
        /// <summary>
        /// 事件类型：Register, Unregister, HealthStatusChanged, Heartbeat
        /// </summary>
        public string EventType { get; set; } = string.Empty;

        /// <summary>
        /// 实例ID
        /// </summary>
        public Guid InstanceId { get; set; }

        /// <summary>
        /// 服务ID
        /// </summary>
        public Guid ServiceId { get; set; }

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 实例标识（业务ID）
        /// </summary>
        public string InstanceIdStr { get; set; } = string.Empty;

        /// <summary>
        /// 实例地址
        /// </summary>
        public string Address { get; set; } = string.Empty;

        /// <summary>
        /// 健康状态
        /// </summary>
        public string HealthStatus { get; set; } = string.Empty;

        /// <summary>
        /// 旧值（用于状态变更事件）
        /// </summary>
        public string? OldValue { get; set; }

        /// <summary>
        /// 新值（用于状态变更事件）
        /// </summary>
        public string? NewValue { get; set; }

        /// <summary>
        /// 变更者
        /// </summary>
        public string ChangedBy { get; set; } = string.Empty;

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 实例详情
        /// </summary>
        public Dictionary<string, object> InstanceDetails { get; set; } = new();
    }

    /// <summary>
    /// 负载均衡配置变更事件
    /// </summary>
    public class LoadBalancingConfigChangedEto : IDistributedEvent
    {
        /// <summary>
        /// 服务ID
        /// </summary>
        public Guid ServiceId { get; set; }

        /// <summary>
        /// 服务名称
        /// </summary>
        public string ServiceName { get; set; } = string.Empty;

        /// <summary>
        /// 事件类型：Create, Update, Delete
        /// </summary>
        public string EventType { get; set; } = string.Empty;

        /// <summary>
        /// 旧的负载均衡策略
        /// </summary>
        public string OldStrategy { get; set; } = string.Empty;

        /// <summary>
        /// 新的负载均衡策略
        /// </summary>
        public string NewStrategy { get; set; } = string.Empty;

        /// <summary>
        /// 变更者
        /// </summary>
        public string ChangedBy { get; set; } = string.Empty;

        /// <summary>
        /// 变更时间
        /// </summary>
        public DateTime ChangeTime { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 配置详情
        /// </summary>
        public Dictionary<string, object> ConfigDetails { get; set; } = new();
    }
}